// pages/integral_detailed/integral_detailed.js
var util = require('../../utils/util.js');
var api = require('../../config/api.js');


Page({

  /**
   * 页面的初始数据
   */
  data: {
    active: 0,
    pointType: "",
    page:1,
    limit:10,
  },



  // 切换
  onChange(event) {
    console.log(event)
    var that = this;
    that.pointType = event.detail.name;
    if(that.pointType == 0) {
      that.pointType = ""
    }

    that.getInregral(that.pointType)
  },

  // 获取明细
  getInregral(pointType) {
    console.log(pointType)
    if (pointType === undefined) {
      pointType = ''
    }
    var that = this;
    util.request(api.IntegralList, {
      pointType: pointType,
      page: that.data.page,
      limit: that.data.limit,
    }, 'get').then(function (res) {
      if (res.errno === 0) {
        that.setData({
          detailedList: res.data
        })
      } else {
        wx.showToast({
          title: res.errmsg,
          icon: 'none',
          duration: 1500
        })

      }


    });
  },





  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    // 获取明细列表
    this.getInregral()
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    if (this.data.totalPages > this.data.page) {
      this.setData({
        page: this.data.page + 1
      });
      this.getData(this.data.dealType)
    } else {
      wx.showToast({
        title: '没有更多明细',
        icon: 'none',
        duration: 2000
      });
      return false;
    }
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})